package com.qf.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCouponUserMapper;
import com.qf.pojo.DtsCouponUser;
import com.qf.service.DtsCouponUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DtsCouponUserServiceImpl implements DtsCouponUserService {

    @Autowired
    DtsCouponUserMapper couponUserMapper;

    @Override
    public IPage<DtsCouponUser> findPage(Integer page, Integer limit, String couponId,String status, String userId, String sort, String order) {
        IPage<DtsCouponUser> iPage = new Page<>(page,limit);
        QueryWrapper<DtsCouponUser> wrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(couponId)){
            wrapper.eq("coupon_id",couponId);
        }

        if(!StringUtils.isEmpty(userId)){
            wrapper.eq("user_id",userId);
        }

        if(!StringUtils.isEmpty(status)){
            wrapper.eq("status",status);
        }

        if(order.equalsIgnoreCase("asc")){
            wrapper.orderByAsc(sort);
        }else {
            wrapper.orderByDesc(sort);
        }

        iPage = couponUserMapper.selectPage(iPage,wrapper);
        return iPage;
    }
}
